package com.muye.dianli.activity;

import java.io.File;

import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.muye.adapter.ShoppingCartAdapter;
import com.muye.constant.C;
import com.muye.dianli.BaseActivity;
import com.muye.dianli.R;

/**
 * 购物车
 * 
 * @author TangChao
 *
 */
public class ShoppingCartActivity extends BaseActivity implements OnClickListener
{
	/**
	 * 列表
	 */
	private PullToRefreshListView listView;
	
	/**
	 * 购物车适配器
	 */
	private ShoppingCartAdapter adapter;
	
	/**
	 * 图片缓存路径
	 */
	private String filePath;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		getWindow().setFormat(PixelFormat.RGBA_8888);
		setContentView(R.layout.shopping_cart_layout);
		createTitle();
		initWidge();
		filePath = C.FILE_PATH + "/DianLi";
		File file = new File(filePath);
		if (!file.exists())
		{
			file.mkdirs();
		}
	}
	
	@Override
	protected void onDestroy()
	{
		super.onDestroy();
	}
	
	/**
	 * 初始化标题栏
	 */
	private void createTitle()
	{
		TextView titleName = (TextView) findViewById(R.id.title_bar_name_text_view);
		titleName.setText("购物车");
		titleName.setTextColor(getResources().getColor(R.color.white));
		ImageView leftBtn = (ImageView) findViewById(R.id.title_bar_left_image_view);
		leftBtn.setImageResource(R.drawable.title_back_icon);
		leftBtn.setVisibility(View.VISIBLE);
		leftBtn.setOnClickListener(this);
	}
	
	/**
	 * 初始化控件
	 */
	private void initWidge()
	{
		listView = (PullToRefreshListView) findViewById(R.id.shopping_cart_layout_list_view);
		if (C.SHOPPING_CART_DATA == null)
		{
			C.showToast(ShoppingCartActivity.this, "购物车是空的");
			return;
		}
		adapter = new ShoppingCartAdapter(C.SHOPPING_CART_DATA, this, filePath);
		listView.setAdapter(adapter);
	}
	
	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
			case R.id.title_bar_left_image_view:
				finish();
				break;
			
			default:
				break;
		}
	}
}
